
/**
* @Title: DropwizardMetricsMBeansAutoConfiguration.java
* @Package com.leetone.metrics.config
* @Description: 【】
* @date 2018年5月10日 下午3:00:41
* @version V1.0
* @Company: 上海未泰信息技术有限公司
* @author:[谭磊][leetone123@163.com]
*/

package com.leetone.metrics.config;

import javax.management.MBeanServer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;

/**
* @ClassName: DropwizardMetricsMBeansAutoConfiguration
* @Description: 【该配置用于将AOP逻辑暴露给使用者】
* @date 2018年5月10日 下午3:00:41
* @Company: 上海未泰信息技术有限公司
* @author:[谭磊][leetone123@163.com]
*/
@Configuration
@ComponentScan({"com.leetone.metrics.aop","com.leetone.metrics.lifecycle"})
@AutoConfigureAfter(AopAutoConfiguration.class)
public class DropwizardMetricsMBeansAutoConfiguration {

	@Value("${metrics.mbeans.domain.name:com.leetone.metrics}")
	String metricsMBeansDomainName;
	@Autowired
	MBeanServer mBeanServer;
	@Autowired
	MetricRegistry metricRegistry;
	
	@Bean
	public JmxReporter jmxReporter()
	{
		JmxReporter reporter = JmxReporter
				.forRegistry(metricRegistry)
				.inDomain(metricsMBeansDomainName)
				.registerWith(mBeanServer)
				.build();
		return reporter;
	}
}
